home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / perl5 / Net / DBus / Binding / Bus.pm next >
Encoding:
Perl POD Document  |  2008-02-20  |  4.5 KB  |  203 lines

  1. # -*- perl -*-
  2. #
  3. # Copyright (C) 2004-2006 Daniel P. Berrange
  4. #
  5. # This program is free software; You can redistribute it and/or modify
  6. # it under the same terms as Perl itself. Either:
  7. #
  8. # a) the GNU General Public License as published by the Free
  9. #   Software Foundation; either version 2, or (at your option) any
  10. #   later version,
  11. #
  12. # or
  13. #
  14. # b) the "Artistic License"
  15. #
  16. # The file "COPYING" distributed along with this file provides full
  17. # details of the terms and conditions of the two licenses.
  18.  
  19. =pod
  20.  
  21. =head1 NAME
  22.  
  23. Net::DBus::Binding::Bus - Handle to a well-known message bus instance
  24.  
  25. =head1 SYNOPSIS
  26.  
  27.   use Net::DBus::Binding::Bus;
  28.  
  29.   # Get a handle to the system bus
  30.   my $bus = Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SYSTEM);
  31.  
  32. =head1 DESCRIPTION
  33.  
  34. This is a specialization of the L<Net::DBus::Binding::Connection>
  35. module providing convenience constructor for connecting to one of
  36. the well-known bus types. There is no reason to use this module
  37. directly, instead get a handle to the bus with the C<session> or
  38. C<system> methods in L<Net::DBus>.
  39.  
  40. =head1 METHODS
  41.  
  42. =over 4
  43.  
  44. =cut
  45.  
  46. package Net::DBus::Binding::Bus;
  47.  
  48. use 5.006;
  49. use strict;
  50. use warnings;
  51.  
  52. use Net::DBus;
  53.  
  54. use base qw(Net::DBus::Binding::Connection);
  55.  
  56. =item my $bus = Net::DBus::Binding::Bus->new(type => $type);
  57.  
  58. =item my $bus = Net::DBus::Binding::Bus->new(address => $addr);
  59.  
  60. Open a connection to a message bus, either a well known bus type
  61. specified using the C<type> parameter, or an arbitrary bus specified
  62. using the C<address> parameter. If the C<private> parameter is set
  63. to a true value, then a private connection to the bus is obtained.
  64. The caller must explicitly disconnect this bus instance before
  65. releasing the last instance of the object.
  66.  
  67. =cut
  68.  
  69. sub new {
  70.     my $proto = shift;
  71.     my $class = ref($proto) || $proto;
  72.     my %params = @_;
  73.     
  74.     my $connection;
  75.     if (defined $params{type}) {
  76.     if ($params{private}) {
  77.         $connection = Net::DBus::Binding::Bus::_open_private($params{type});
  78.     } else {
  79.         $connection = Net::DBus::Binding::Bus::_open($params{type});
  80.     }
  81.     } elsif (defined $params{address}) {
  82.     if ($params{private}) {
  83.         $connection = Net::DBus::Binding::Connection::_open_private($params{address});
  84.     } else {
  85.         $connection = Net::DBus::Binding::Connection::_open($params{address});
  86.     }
  87.     $connection->dbus_bus_register();
  88.     } else {
  89.     die "either type or address parameter is required";
  90.     }
  91.       
  92.     my $self = $class->SUPER::new(%params, connection => $connection);
  93.  
  94.     bless $self, $class;
  95.  
  96.     return $self;
  97. }
  98.  
  99.  
  100. =item $bus->request_name($service_name)
  101.  
  102. Send a request to the bus registering the well known name 
  103. specified in the C<$service_name> parameter. If another client
  104. already owns the name, registration will be queued up, pending
  105. the exit of the other client.
  106.  
  107. =cut
  108.  
  109. sub request_name {
  110.     my $self = shift;
  111.     my $service_name = shift;
  112.     
  113.     $self->{connection}->dbus_bus_request_name($service_name);
  114. }
  115.  
  116. =item my $name = $bus->get_unique_name
  117.  
  118. Returns the unique name by which this processes' connection to
  119. the bus is known. Unique names are never re-used for the entire
  120. lifetime of the bus daemon.
  121.  
  122. =cut
  123.  
  124. sub get_unique_name {
  125.     my $self = shift;
  126.  
  127.     $self->{connection}->dbus_bus_get_unique_name;
  128. }
  129.  
  130.  
  131. =item $bus->add_match($rule)
  132.  
  133. Register a signal match rule with the bus controller, allowing
  134. matching broadcast signals to routed to this client.
  135.  
  136. =cut
  137.  
  138. sub add_match {
  139.     my $self = shift;
  140.     my $rule = shift;
  141.     
  142.     $self->{connection}->dbus_bus_add_match($rule);
  143. }
  144.  
  145. =item $bus->remove_match($rule)
  146.  
  147. Unregister a signal match rule with the bus controller, preventing
  148. further broadcast signals being routed to this client
  149.  
  150. =cut
  151.  
  152. sub remove_match {
  153.     my $self = shift;
  154.     my $rule = shift;
  155.     
  156.     $self->{connection}->dbus_bus_remove_match($rule);
  157. }
  158.  
  159. sub DESTROY {
  160.     # Keep autoloader quiet
  161. }
  162.  
  163. sub AUTOLOAD {
  164.     # This AUTOLOAD is used to 'autoload' constants from the constant()
  165.     # XS function.
  166.  
  167.     my $constname;
  168.     our $AUTOLOAD;
  169.     ($constname = $AUTOLOAD) =~ s/.*:://;
  170.  
  171.     die "&Net::DBus::Binding::Bus::constant not defined" if $constname eq '_constant';
  172.  
  173.     if (!exists $Net::DBus::Binding::Bus::_constants{$constname}) {
  174.         die "no such method $constname, and no constant \$Net::DBus::Binding::Bus::$constname";
  175.     }
  176.  
  177.     {
  178.     no strict 'refs';
  179.     *$AUTOLOAD = sub { $Net::DBus::Binding::Bus::_constants{$constname} };
  180.     }
  181.     goto &$AUTOLOAD;
  182. }
  183.  
  184. 1;
  185.  
  186. =pod
  187.  
  188. =back
  189.  
  190. =head1 SEE ALSO
  191.  
  192. L<Net::DBus::Binding::Connection>, L<Net::DBus>
  193.  
  194. =head1 AUTHOR
  195.  
  196. Daniel Berrange E<lt>dan@berrange.comE<gt>
  197.  
  198. =head1 COPYRIGHT
  199.  
  200. Copyright 2004-2005 by Daniel Berrange
  201.  
  202. =cut
  203.